package com.gxa.controller.fygl.sfxmwh;

import com.gxa.pojo.dto.fygl.sfxmwh.CharTypeDto;
import com.gxa.pojo.entity.fygl.sfxmwh.CharType;
import com.gxa.service.fygl.sfxmwh.QueryAllService;
import com.gxa.utils.QueryResult;
import com.gxa.utils.Result;
import com.gxa.utils.ResultUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author：hubalabala
 */
@RestController
@RequestMapping("/type")
public class QueryAllController {
    @Resource
    private QueryAllService queryAllService;


    @GetMapping("/queryAll")
    public Result queryAll(CharTypeDto charTypeDto){
        QueryResult queryResult = queryAllService.queryAll(charTypeDto);
        return ResultUtils.buildSuccess(queryResult.getData(),queryResult.getCount());
    }

    @RequestMapping("/add")
    public Result addType(@RequestBody CharType charType){

         queryAllService.add(charType);
         return ResultUtils.buildSuccess();
    }

    @PostMapping("/update")
    public Result updateType(@RequestBody CharType charType){
        queryAllService.update(charType);
        return ResultUtils.buildSuccess();
    }

    @RequestMapping("/delete")
    public Result deleteType(String proName){
        queryAllService.delete(proName);
        return ResultUtils.buildSuccess();
    }

    @GetMapping("/find")
    public Result findTypeByName(CharTypeDto charTypeDto){
        System.out.println(charTypeDto);
        QueryResult queryResult = queryAllService.findByName(charTypeDto);

        return ResultUtils.buildSuccess(queryResult.getData(),queryResult.getCount());
    }
//    @GetMapping("/find")
//    public Result findTypeByName(String proName){
//        System.out.println(proName);
//        CharType charType = new CharType();
//        charType = queryAllService.findByName(proName);
//        return ResultUtils.buildSuccess(charType);
//    }

//    @GetMapping("/find")
//    public Result findTypeByName(@RequestBody CharType charType){
//        CharType charType1 = new CharType();
//        charType1 = queryAllService.findByName(charType.getProName());
//        return ResultUtils.buildSuccess(charType1);
//    }

}
